package com.woniuxy.micromemberserver.controller;

import com.github.pagehelper.PageInfo;
import com.slsupermarket.common.res.ResponseMsg;
import com.woniuxy.micromemberserver.bean.MemberTypeBean;
import com.woniuxy.micromemberserver.bean.PageRequest;
import com.woniuxy.micromemberserver.service.IMemberTypeService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会员类型表现层
 * @Author hz
 */
@RequestMapping("/memberType")
@RestController
public class MemberTypeController {

    @Resource
    private IMemberTypeService memberTypeServiceImpl;

    /**
     * 条件分页查询
     * @param request
     * @param memberTypeBean
     * @return
     */
    @GetMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg findAll(PageRequest request, MemberTypeBean memberTypeBean){
        PageInfo<MemberTypeBean> pageInfo = memberTypeServiceImpl.findAllByParams(request,memberTypeBean);
        System.out.println(pageInfo);
        return ResponseMsg.builder().code(200).msg("查询").data(pageInfo.getList()).build();
    }

    /**
     * 新增会员类型
     * @param memberTypeBean
     * @return
     */
    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg save(MemberTypeBean memberTypeBean){
        memberTypeServiceImpl.saveMemberType(memberTypeBean);
        return ResponseMsg.builder().code(200).msg("新增").build();
    }

    /**
     * 修改会员类型（或删除：仅修改删除标记）
     * @param memberTypeBean
     * @return
     */
    @PutMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseMsg update(MemberTypeBean memberTypeBean){
        memberTypeServiceImpl.updateMemberType(memberTypeBean);
        return ResponseMsg.builder().code(200).msg("修改").build();
    }

}
